package sk.upjs.ariadne.editor.data;

import java.io.File;
import java.util.*;

/**
 * Represents an indoor map.
 */
public class IndoorMap {

	private File mapFile;

	/**
	 * Collection of all nodes contained in this layer.
	 */
	private Collection<MapNode> nodes = new HashSet<MapNode>();

	/**
	 * Collection of all walls contained in this layer.
	 */
	private Collection<MapWall> walls = new HashSet<MapWall>();

	/**
	 * Creates a new indoor map that is not associated to a file
	 */
	public IndoorMap() {
		this(null);
	}

	/**
	 * Creates a new indoor map that is
	 * 
	 * @param file
	 */
	public IndoorMap(File file) {
		mapFile = file;
		if (mapFile != null)
			loadFromFile();
	}

	/**
	 * Returns a collection of nodes that are contained in this map.
	 */
	public Collection<MapNode> getNodes() {
		return nodes;
	}

	/**
	 * Returns a collection of walls that are contained in this map.
	 */
	public Collection<MapWall> getWalls() {
		return walls;
	}

	/**
	 * Loads an indoor map from an xml file
	 */
	private void loadFromFile() {
		// TODO
	}

	/**
	 * Assigns to all map elements an unique id. If a map elements has an
	 * assigned ID, then this ID is never changed (since it can be referenced
	 * from other resources).
	 */
	private void generatedIDs() {
		// TODO
	}

	/**
	 * Checks whether all referenced map elements (e.g. end nodes of a wall) are
	 * contained in this map.
	 * 
	 * @return true, if objects contained in this map are consistent, false
	 *         otherwise
	 */
	public boolean checkConsistency() {
		return false;
		// TODO
	}

	public void saveTo(File file) {
		System.out.println("Saving ...");
		// TODO
	}

	public void saveAs(File file) {
		saveTo(file);
		mapFile = file;
	}

	public void save() {
		saveTo(mapFile);
	}
}
